#include "utils.hh"

map<string, string> Utils::readConf()
{
    map<string, string> myMap;
    string filename = "/home/tk/review/project/conf/myconf.conf";
    ifstream file(filename);
    if (file.is_open())
    {
        string line;
        while (getline(file, line))
        {
            istringstream iss(line);
            string key, value;
            if (iss >> key >> value)
            {
                myMap[key] = value;
            }
        }
        file.close();
    }
    return myMap;
}

size_t Utils::nBytesCode(const char ch)
{
    if (ch & (1 << 7))
    {
        int nBytes = 1;
        for (int idx = 0; idx != 6; ++idx)
        {
            if (ch & (1 << (6 - idx)))
            {
                ++nBytes;
            }
            else
            {
                break;
            }
        }
        return nBytes;
    }
    return 1;
}

#if 0
int main(int argc, char const *argv[])
{
    map<string,string> myM = Utils::readConf();
    cout << myM["stop_words_zh.txt"] << "\n";
    return 0;
}
#endif
